package com.java.yz.day11.ketang;

import java.util.ArrayList;

//集合的嵌套遍历
public class ListText4 {
    public static void main(String[] args) {
        //创建集合类
        ArrayList<ArrayList<Student>> arrayLists = new ArrayList<>();
        ArrayList<Student> students = new ArrayList<>();
        //创建一个班级学生类
        Student s1 = new Student("张翰", 19);
        Student s2 = new Student("张勇", 20);
        Student s3 = new Student("张宇", 21);
        Student s4 = new Student("张翰", 19);

        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);
        arrayLists.add(students); //还要把学生加到班级里面去

        ArrayList<Student> students1 = new ArrayList<>();
        students1.add(new Student("小胡",16));
        students1.add(new Student("小黑",21));
        students1.add(new Student("小洪",20));
        students1.add(new Student("小杨",19));
        arrayLists.add(students1);
//        for (int i = 0; i < arrayLists.size(); i++) {
//            for (int j = 0; j < students.size(); j++) {
//                System.out.println(j);
//            }
//        }

        for (ArrayList<Student> arrayList : arrayLists) {
            System.out.println("-----------------------");
            for (Student student: arrayList) {
                System.out.println(student);
            }
        }
//        //使用增强for循环 这只遍历内部的学生，外面还可以遍历班级
//        for (Student student : students) {
//            System.out.println(student);
//        }

    }
}
